<template>
  <div class="carcheck">
    <van-nav-bar left-text="返回" left-arrow @click-left="onClickLeft" />

    <div class="add">
      <div class="top bg_ff">
        <div class="address">
          <div class="address-l pd10">收货地址</div>
          <div class="address-r pd510">></div>
        </div>
        <div class="detail">
          <p class="pd5">{{ add[0].name }}</p>
          <p class="pd5">{{ add[0].tel }}</p>
        </div>
        <p class="detail-address pd5">{{ add[0].address }}</p>
      </div>
    </div>

    <div class="goods">
      <ul>
        <li v-for="(item, index) in orderlist" :key="index" class="main bg_ff">
          <div class="main-l">
            <img :src="item.t.picUrl" alt="" />
          </div>
          <div class="main-r">
            <p class="main-top">{{ item.t.goodsName }}</p>
            <div
              v-for="(child, index) in item.t.specifications"
              :key="index"
              class="middle"
            >
              <p class="p">{{ child }}</p>
            </div>
            <div class="price">
              <p class="price-l">￥{{ item.t.price }}.00</p>
              <p class="price-r">X {{ item.t.number }}</p>
            </div>
          </div>
        </li>
      </ul>
    </div>

    <div class="bottom">
      <div class="f">
        <p class="bottom-l">商品金额</p>
        <p class="bottom-r">￥ {{ total }}元</p>
      </div>
      <div class="f">
        <p class="bottom-l">油费</p>
        <p class="bottom-r">￥ 0.00</p>
      </div>
      <div class="order">
        <span>订单备注</span>
        <input type="text" placeholder="请输入备注" />
      </div>
    </div>

    <van-submit-bar :price="total" button-text="提交订单" @submit="onSubmit" />
  </div>
</template>

<script>
import { addressList } from "../../assets/api/addrapi.js";
export default {
  data() {
    return {
      orderlist: [],
      add: [],
      total: 0,
    };
  },
  mounted() {
    let J = JSON.parse(this.$store.state.orderlist);
    this.orderlist = J;
    console.log(this.orderlist);
    this.getPrice();
  },
  created() {
    this.getAdd();
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    getAdd() {
      addressList().then((r) => {
        // console.log(r.data.data.list)
        this.add = r.data.data.list;
        for (let x in r.data.data.list) {
          this.add[x].address =
            r.data.data.list[x].province +
            r.data.data.list[x].city +
            r.data.data.list[x].county;
        }
        // console.log(this.add)
      });
    },
    getPrice() {
      let sum = 0;
      console.log(this.orderlist);
      for (let x in this.orderlist) {
        sum += this.orderlist[x].t.price * this.orderlist[x].t.number;
      }
      this.total = sum * 100;
    },
    onSubmit() {},
  },
};
</script>

<style lang="scss" scoped>
.carcheck {
  margin-bottom: 49.98px;
  .goods {
    img {
      width: 88px;
      height: 88px;
    }
  }
}
.top {
  width: 100%;
  height: 90px;
  padding-bottom: 20px;
}
.detail,
.detail-address {
  display: flex;
  line-height: 20px;
  height: 20px;
  font-size: 13px;
}
.address {
  padding-top: 10px;
  font-weight: 900;
  display: flex;
  justify-content: space-between;
}
.address-r {
  margin-right: 20px;
  margin-top: 3px;
}
.main {
  margin-top: 15px;
  display: flex;
}
.goods {
  .main-top {
    font-weight: 600;
  }
  .main-l {
    margin-left: 10px;
  }
  .main-r {
    width: 70%;
    margin-top: 5px;
    .middle {
      p {
        font-size: 12px;
        border: 1px solid rgb(216, 216, 217);
        color: rgb(216, 216, 217);
        display: block;
        width: 30px;
        text-align: center;
        margin-top: 10px;
      }
    }
    .price {
      margin-top: 20px;
      display: flex;
      justify-content: space-between;
      .price-l {
        font-weight: 600;
      }
      .price-r {
        margin-right: 10px;
      }
    }
  }
}
.bottom {
  background-color: #fff;
  padding: 20px;
  .f {
    display: flex;
    justify-content: space-between;
    height: 40px;
    line-height: 40px;
    .bottom-r {
      color: rgb(243, 38, 41);
    }
  }
  .order {
    margin-top: 10px;
    input {
      margin-left: 50px;
      border: none;
      outline: none;
      font-size: 14px;
    }
  }
}
input::-webkit-input-placeholder {
  color: #c0c0c0;
}
</style>